package com.hgyc.mom.common.print;

import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * hiprint拖拽组件转换工具
 * @author fwj
 * @since 2024/6/26
 */
public class PrintElementConverter {

    /**
     * 转换
     * @param fieldList 字段
     * @return 拖拽组件
     */
    public static List<PrintElementType> convert(List<PrintTemplateDataField> fieldList) {
        List<PrintElementType> typeList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(fieldList)) {
            for (PrintTemplateDataField field : fieldList) {
                PrintElementType type = new PrintElementType();
                type.setTid(field.getObjectName()+"."+field.getFieldName());
                type.setText(field.getDescription());

                Class fieldType = field.getType();

                // 根据字段的类型进行不同的操作
                if (fieldType == Integer.class) {
                    //TODO 参考hiprint.bundle.js 10000行的类型
                } else if (fieldType == String.class) {
                    type.setType("text");
                } else if (fieldType == Double.class) {

                } else {

                }

                //特殊处理公共字段 barcode
                if (Objects.equals("barcode", field.getFieldName())) {
                    type.setType("qrcode");
                }

                //设置默认属性
                PrintElementTypeOption options = new PrintElementTypeOption();
                options.setTitle(field.getDescription());
                options.setField(field.getFieldName());
                options.setHeight(18);
                options.setFontSize(14);
                options.setFontWeight("700");
                options.setTextAlign("center");
                options.setTextContentVerticalAlign("middle");
                type.setOptions(options);

                typeList.add(type);
            }
        }
        return typeList;
    }

}
